package vista;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;


import negocio.beans.central.Proveedor;
import controlador.CasaCentral;


public class ProveedoresModificacion extends javax.swing.JFrame {
	
	private static final long serialVersionUID = 1L;
	private JTextField txtCUIT;
	private JTextField txtRazonSocial;
	private JTextField txtCondicionCompra;
	private JLabel lblCondicionCompra;
	private JButton btnAceptar;
	private JTextField txtTipo;
	private JTextField txtDireccion;
	private JLabel lblTipo;
	private JLabel lblDireccion;
	private JLabel lblRazonSocial;
	private JLabel lblCUIT;
	private JTable tblProveedores;
	
	private Proveedor proveedor;

	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ProveedoresModificacion inst = new ProveedoresModificacion();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public ProveedoresModificacion() {
		super();
		initGUI();
		CentrarJFrame();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setBackground(new java.awt.Color(202,203,251));
			getContentPane().setLayout(null);
			this.setTitle("Modificacion Proveedor");
			this.setResizable(false);
			pack();
			this.setSize(331, 300);
			
			{
				txtCUIT = new JTextField();
				getContentPane().add(txtCUIT);
				txtCUIT.setBounds(141, 30, 138, 21);
			}
			{
				txtRazonSocial = new JTextField();
				getContentPane().add(txtRazonSocial);
				txtRazonSocial.setBounds(141, 63, 138, 21);
			}
			{
				lblCUIT = new JLabel();
				getContentPane().add(lblCUIT);
				lblCUIT.setText("CUIT:");
				lblCUIT.setBounds(7, 30, 79, 14);
			}
			{
				lblRazonSocial = new JLabel();
				getContentPane().add(lblRazonSocial);
				lblRazonSocial.setText("Razon Social:");
				lblRazonSocial.setBounds(7, 63, 92, 14);
			}
			{
				lblDireccion = new JLabel();
				getContentPane().add(lblDireccion);
				lblDireccion.setText("Direccion:");
				lblDireccion.setBounds(7, 94, 79, 14);
			}
			{
				lblTipo = new JLabel();
				getContentPane().add(lblTipo);
				lblTipo.setText("Tipo:");
				lblTipo.setBounds(7, 127, 79, 14);
			}
			{
				txtDireccion = new JTextField();
				getContentPane().add(txtDireccion);
				txtDireccion.setBounds(141, 94, 138, 21);
			}
			{
				txtTipo = new JTextField();
				getContentPane().add(txtTipo);
				txtTipo.setBounds(141, 127, 138, 21);
			}
			
			{
				lblCondicionCompra = new JLabel();
				getContentPane().add(lblCondicionCompra);
				lblCondicionCompra.setText("Condicion Compra:");
				lblCondicionCompra.setBounds(7, 161, 134, 16);
			}
			{
				txtCondicionCompra = new JTextField();
				getContentPane().add(txtCondicionCompra);
				txtCondicionCompra.setBounds(141, 158, 138, 23);
			}
			
			{
				btnAceptar = new JButton();
				getContentPane().add(btnAceptar);
				btnAceptar.setText("Aceptar");
				btnAceptar.setBounds(105, 211, 99, 21);
				btnAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						
						CasaCentral.getInstancia().modificacionProveedor(txtRazonSocial.getText(), txtDireccion.getText(), txtTipo.getText(),txtCondicionCompra.getText());
						dispose();
						
					}
				});
			}
			
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

	public void setProveedor(Proveedor proveedor) {
		this.proveedor = proveedor;
		txtCUIT.setText(proveedor.getCuit());
		txtRazonSocial.setText(proveedor.getRazonSocial());
		txtDireccion.setText(proveedor.getDireccion());
		txtTipo.setText(proveedor.getTipoProveedor());
		txtCondicionCompra.setText(proveedor.getCondicionCompra());
	}

	public Proveedor getProveedor() {
		return proveedor;
	}
	
	public void setTblProveedores(JTable proveedores){
		this.tblProveedores = proveedores; 
	}
	public JTable getTblProveedores(){
		return tblProveedores; 
	}
	
	private void CentrarJFrame(){
		
	    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
	    
	    
	    int w = this.getSize().width;
	    int h = this.getSize().height;
	    int x = (dim.width-w)/2;
	    int y = (dim.height-h)/2;
	    
	    
	    this.setLocation(x, y);
	}
}
